﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.Threading;
using System.Globalization;
using University.Workshop.DataAccess.LanguagePack.ClientLanguagePack;

namespace University.Workshop.ClientApp
{
    /// <summary>
    /// Interaction logic for MiniGames.xaml
    /// </summary>
    public partial class MiniGame : Window
    {
        private string GameNot;
        private string NoChip;

        User user;
        Wheel wheel = null;
        LuckWithoutWhite luck = null;
        Good good = null;
        selectCar little = null;
        MiniGames.Roulette.Roulette RoulleteSort = null;
        public bool Banned = false;
        string language;
        public MiniGame(User userReceived,string languageReceived)
        {
            InitializeComponent();
            language = languageReceived;
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
            ApplyLanguage();
            user = userReceived;
        }

        private void ApplyLanguage()
        {
            label1.Content = ClientLanguagePack.MiniGameLabelSelect;
            this.NoChip = ClientLanguagePack.MiniGamesNoChips;
            this.GameNot = ClientLanguagePack.MiniGamesGameNotAvailable;
        }
        private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (user.Chips > 0)
            {
                Client client = new Client();
                if (client.GetGameStatus(user, "Wheel"))
                {
                    wheel = new Wheel(user, false,language);
                    wheel.ShowDialog();
                }
                else
                    MessageBox.Show(this.GameNot);

            }
            else
                MessageBox.Show(this.NoChip);
        }

        private void ListBoxItem_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
        {
            luck = new LuckWithoutWhite(user);
            luck.ShowDialog();
        }

        private void ListBoxItem_MouseDoubleClick_2(object sender, MouseButtonEventArgs e)
        {
            Client client = new Client();
            if (client.GetGameStatus(user, "Luck") == true)
            {
                good = new Good(user);
                good.ShowDialog();
            }
            else
            {
                MessageBox.Show(this.GameNot, "Ups");
            }
            
        }

        private void ListBoxItem_MouseDoubleClick_3(object sender, MouseButtonEventArgs e)
        {
            Client client = new Client();
            if (client.GetGameStatus(user, "Races") == true)
            {
                little = new selectCar(user,language);
                little.ShowDialog();
            }
            else
            {
                MessageBox.Show(this.GameNot, "Ups");
            }
        }

        private void ListBoxItem_MouseDoubleClick_4(object sender, MouseButtonEventArgs e)
        {
            if (user.Chips > 0)
            {
                Client client = new Client();
                if ( client.GetGameStatus(user, "Roulette") == true )
                {
                    if (user.Chips > 50)
                    {
                        RoulleteSort = new MiniGames.Roulette.Roulette(user, user.Chips, this.language);
                        RoulleteSort.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(this.NoChip, "Ups");
                    }
                }
                else
                {
                    MessageBox.Show(this.GameNot, "Ups");
                }
            }
        }

        private void ListBoxItem_Selected(object sender, RoutedEventArgs e)
        {

        }
        public void Ban()
        { 
                if (wheel != null)
                {
                    wheel.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                  new Action(delegate()
                  {

                      if (wheel.IsLoaded)
                      {
                          wheel.Ban();    
                           
                      }

                  }));
                }

                if (luck != null)
                {
                    luck.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                  new Action(delegate()
                  {

                      if (luck.IsLoaded)
                      {
                          luck.Ban();
                      }

                  }));
                }

                if (good != null)
                {
                    good.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                  new Action(delegate()
                  {

                      if (good.IsLoaded)
                      {
                          good.Ban();
                      }

                  }));
                }

                if (little != null)
                {
                    little.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                  new Action(delegate()
                  {

                      if (little.IsLoaded)
                      {
                          little.Ban();
                      }

                  }));
                }

                if (RoulleteSort != null)
                {
                    RoulleteSort.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                  new Action(delegate()
                  {

                      if (RoulleteSort.IsLoaded)
                      {
                          RoulleteSort.Close();
                      }

                  }));
                }
            }

        
        private void Window_Closed(object sender, EventArgs e)
        {
        


            
        }

        private void ListBoxItem_Selected_1(object sender, RoutedEventArgs e)
        {

        }
        
    }
}
